#include <stdio.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h> 


int main()
{
  pid_t pid = fork();
  if(pid==-1)
  {
    perror("fork");
    exit(1);
  }
  else if(pid==0)
  {
    sleep(20);
    exit(10);
  }
  else
  {
    int status;
    int ret=waitpid(pid,&status,0);
    if(ret>0&& (status & 0x7F )==0) //正常退出
    {
      printf("child exit code :%d\n",(status>>8)&0xFF);
    }
    else if(ret>0)//异常退出
    {
      printf("sig code: %d\n",status & 0x7F);
    }
  }

}
